import React from 'react';
import {injectIntl} from './intl';
import PropTypes from 'prop-types';
import ExcelImport from '../common/ExcelImport';
import fileTemplate from '../attachment/维修模式导入模板.xlsx';
import Return from '../common/Return';
const basePath = fetch.basePath || '';

class FileImport extends React.PureComponent {
    constructor(props) {
        super(props);
        this.state = {
            loading: false,
            hasOperat: false,
        };
    }

    beforeUpload = () => this.setState({loading: true});

    afterUpload = () => {
        this.setState({
            loading: false,
        });
    };

    render() {
        const description = [
            this.props.intl.formatMessage({
                id: 'fileImportRepairMode.step2.description1',
                defaultMessage: '编号、名称 不能为空；'
            }),
            this.props.intl.formatMessage({
                id: 'fileImportRepairMode.step2.description2',
                defaultMessage: '编号不能重复；'
            }),
        ];

        return (<React.Fragment>
            <ExcelImport
                key="import"
                template={fileTemplate}
                templateName={this.props.intl.formatMessage({
                    id: 'fileImportRepairMode.templateName',
                    defaultMessage: '维修模式导入模板'
                })}
                action={`${basePath}/afterSales/api/v1/repairModes/import`}
                description={description}
                beforeUpload={this.beforeUpload}
                afterUpload={this.afterUpload} />
            <div className="page-toolbar">
                <Return
                    disabled={this.state.loading}
                    onConfirm={this.props.onCancel} />
            </div>
        </React.Fragment>);
    }
}


FileImport.propTypes = {
    intl: PropTypes.object,
    onCancel: PropTypes.func,
};
import {connect} from 'react-redux';
const mapDispatchToProps = (dispatch, ownProps) => ({
    onCancel: () => {
        ownProps.history.goBack();
    },
});

export default connect(
    null,
    mapDispatchToProps
)(injectIntl(FileImport));

